package com.ly.feishu.controller;

import com.ly.feishu.entity.dto.AddTaskUserRequest;
import com.ly.feishu.entity.dto.NotificationRequest;
import com.ly.feishu.entity.dto.TaskRequest;
import com.ly.feishu.service.FeishuMessageService;
import com.ly.feishu.service.FeishuTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiuYang
 * @since 2025/8/14 22:01
 **/
@RestController
@RequestMapping("/api/tasks")
public class TaskController {

    @Autowired
    private FeishuMessageService messageService;

    @Autowired
    private FeishuTaskService taskService;

    /**
     * 发送消息卡片给员工
     */
    @PostMapping("/notify")
    public ResponseEntity<String> sendNotification(@RequestBody NotificationRequest request) {
        messageService.sendPersonalCard(
                request.getMobile(),
                request.getTitle(),
                request.getContent(),
                request.getBtnText(),
                request.getBtnUrl()
        );
        return ResponseEntity.ok("消息已发送");
    }

    /**
     * 创建任务
     */
    @PostMapping("/task")
    public ResponseEntity<String> createTask(@RequestBody TaskRequest request) {
        String taskId = taskService.createTask(request);
        return ResponseEntity.ok("任务创建成功，ID: " + taskId);
    }

    /**
     * 添加任务成员
     */
    @PostMapping("/addTaskUser")
    public ResponseEntity<String> addTaskUser(@RequestBody AddTaskUserRequest request) {
        taskService.addTaskUser(request);
        return ResponseEntity.ok("任务成员添加成功");
    }

}
